/**
 * Created by no1 on 2014/12/11.
 */

var cluster = require('cluster');
//var numCPUs = require('os').cpus().length;
var numCPUs=10;
var C = require('./config');
var app = require('./servers/apiHTTP');


if (cluster.isMaster) {
    // Fork workers.
    for (var i = 0; i < numCPUs; i++) {
        cluster.fork();
    }
    cluster.on('exit', function (worker, code, signal) {
        console.log('API worker ' + worker.process.pid + ' died');
        cluster.fork();
    });
} else {
    app.listen(C.apiPort);
    console.log('API server is listening on ' + C.apiPort + ' port.');
}

//if (!module.parent) {
//  app.listen(C.apiPort);
//}

